Online-Academy

Look, Read, Understand, Apply

Menu

Java_Q and A 2023

What is Java Beans?

Java Beans are reusable components. It is a class having no-argument constructor with getter and setter methods for its attributes; the class implements Serializable interface.

How are Java beans class used in JSP?

Following tags are used to access Java Beans in JSP:

  • jsp:usebean
  • jsp:getProperty
  • jsp:setProperty

What are the JSP elements?

  • Scriptlet tag <% ... %>
  • Expression tag <%= ... %>
  • Declaration tag <! ... %>

What are JSP Directives?

JSP directives tell web container about translating JSP to corresponding servlet. There are three types of JSP directives:

  • Page Directive: <%@ page attribute='value' %>
    Page directive is used to declare attribute that is visible to an entire JSP page.
  • include Directive: <%@ include file='file name' %>
    Include directive is used to include contents of another file, file may be jsp, html or text file.
  • taglib Directive: <%@ taglib uri='' prefix='' %>
    Taglib directive is used to define custom tags

How is session set and retrieved in JSP?

Setting session: session.setAttribute("name of attribute", "value of attribute");
Retrieving session: session.getAttribute("name of attribute");

What is servlet

Servlet is a technology to create web applications, is a class that extends capabilities of web server

How is servlet created?

Servlet can be created using anyone of following methods:

  • extending HttpServlet class
  • exteinding GenerticServlet class
  • implementing Servlet interface

How is servlet different from CGI?

CGI (common gateway interface) is a technology to handle client requests. In this technology, enables server to call external program to process the HTTP request information. Each request is handles by separate process.
Servlet performs better than CGI, it is protable and secure as it is written in Java. Servlet creates thread to handle each HTTP request.

What are the parameters passed to doGet or doPost method of servlet class?

Parametes are: HttpServletRequest object, and HttpServletResponse object

Which exceptions need to be handled by servlet?

Exceptions thrown: ClassNotFoundException, ServletException, FileNotFoundException

How is servlet deployed in apache tomcat?

Create folder for web application inside webapps folder of apache tomcat webserver. Inside that folder create folders: src, lib, classes and a web.xml (deployment descriptor) file. Inside src folder store Java classes. Inside classes folder save complied Java Classes. In the web.xml (deployment descriptor) specify name of servlet, servlet class, url pattern. Web.xml is an xml file containing information about the servlet.